<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        输出100-200之间所有的质数
    </div>
    <div>
        封装一个函数，这个函数的作用数，用户输入两个数，输出这个之间所有的质数
    </div>
    <input type="text" id="num1">
    <input type="text" id="num2">
    <button id="btn">提交</button>
    <div id="res">

    </div>
    <script>
        // for ( var i = 100 ; i <= 200 ; i ++ ) {
        //     var a = parseInt(i/2);
        //     var num = 0 ;
        //     for ( var b = 2 ; b <= a ; b ++ ) {
        //         if ( i % b == 0 ) {
        //             num ++ ;
        //         }
        //     }
        //     if ( num == 0 ) {
        //         console.log(i);
        //     }
        // }
        function isPrime (a) {
            var flag ;
            if ( a == 2 ) {
                flag = false ;
            }
            for ( var i = 2 ; i < a ; i ++ ) {
                if ( a % i == 0 ) {
                    flag = true ;
                    break;
                } else {
                    flag = false ;
                }
            }
            // console.log(flag);
            return flag ; 
        }
        function atobPrime (a,b) {
            var str = '' ;
            var num = 0 ;
            for ( var i = a ; i <= b ; i ++ ) {
                // console.log(isPrime(i));
                if ( isPrime(i) == false ) {
                    num ++ ;
                    str = str + "&nbsp;&nbsp;" + i ;
                    if ( num % 10 == 0 ) {
                        str = str + "</br>" ;
                    }
                }
            }
            return str ;
        }
        var num1 = document.getElementById("num1");
        var num2 = document.getElementById("num2");
        var btn = document.getElementById("btn");
        btn.onclick = function () {
            var a = parseInt(num1.value);
            var b = parseInt(num2.value);
            console.log(a,b);
            document.getElementById("res").innerHTML = atobPrime(a,b);
        }
    </script>
</body>
</html>